import axios from 'axios';
import appConfig from "../common/config.js"

const service = axios.create({
    baseURL: appConfig.serverUrl,
    headers:{
        "Content-Type":"application/json",
        'X-Requested-With': 'XMLHttpRequest',
    },
});

service.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject(new Error("响应状态码错误"));
        }
    },
    error => {
        return Promise.reject(error);
    }
);

export default service;
